﻿@model IndoReputation.Models.BusinessObject.Collections.NewsJoinList       

@{
    ViewBag.Title = "List News";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>List News</h2>
<div class="grid-main">    
    @(Html.Telerik().Grid(Model)
        .Name("Grid")
        .DataKeys(keys =>
        {
            keys.Add(p => p.ID);
        })
        .ToolBar(toolbar => toolbar.Template(@<text>@item.CustomCommandToolBarButton("insertnew", "Add new News", "Add", "News", null, false, GridButtonType.Text)</text>))
        .Columns(columns =>
        {
            columns.Bound(o => o.No).Width(20);
            columns.Bound(o => o.FlagPath).ClientTemplate("<img alt='Indoreputation' src='" + Url.Content("~/Upload/" + "<#= FlagPath #>") + "'" + " width='20' height='14' />").Title("From").Width(25).Filterable(false);
            columns.Bound(o => o.IsNewspaper).ClientTemplate("<# if (IsNewspaper) { #> <img alt='img-media-newspaper' src='" + Url.Content("~/Content/img/news2424.png") + "'/>" + "<# } else { #> <img alt='img-media-newspaper' src='' /> <# } #>").Title("").Width(35).HtmlAttributes(new { style = "text-align: center" }).Filterable(false);
            columns.Bound(o => o.IsRadio).Hidden();
            columns.Bound(o => o.IsTV).Hidden();
            columns.Bound(o => o.IsOnlineNews).Hidden();
            columns.Bound(o => o.IsOnline).Hidden();
            columns.Bound(o => o.Title).Width(200).ClientTemplate("<a title='' href='' target='_blank' rel='link-title'>" + "<#= Title #>" + "</a>").HtmlAttributes(new { @class = "td-listnews-title" });
            columns.Bound(o => o.Link).Hidden();
            columns.Bound(o => o.AvgMark).Hidden();
            columns.Bound(o => o.MediaName).Title("Media").Width(80);
            columns.Bound(o => o.CreateAt).Format("{0:dd/MM/yyyy HH:mm:ss}").Width(95);
            columns.Bound(o => o.IsPublished).ClientTemplate("<# if (IsPublished) { #> <img alt='<#= IsPublished #>' src='" + Url.Content("~/Content/img/accept.png") + "'/>" + "<# } else { #> <img alt='<#= IsPublished #>' src='" + Url.Content("~/Content/img/remove.png") + "' /> <# } #>").Title("Published").Width(50).HtmlAttributes(new { style = "text-align: center" });
            columns.Command(commands =>
            {
                commands.Custom("viewDetail")
                    .Text("Edit")
                    .DataRouteValues(route => route.Add(o => o.ID).RouteKey("newsID"))
                    .Ajax(false)
                    .Action("Edit", "News")
                    .HtmlAttributes(new { style = "text-align: center" });
                commands.Delete();
            })
            .Width(100);

        })
        .DataBinding(dataBinding =>
        {
            dataBinding.Server().Select("Index", "News", new { ajax = ViewData["ajax"] });
            dataBinding.Ajax().Select("_Index", "News").Enabled((bool)ViewData["ajax"])
                .Delete("_DeleteAjaxEditing", "News");
        })
        .Selectable()
        .Scrollable(scrolling => scrolling.Enabled((bool)ViewData["scrolling"]))
        .Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
        .Pageable(paging => paging.PageSize(20).Enabled((bool)ViewData["paging"]))
        .Filterable(filtering => filtering.Enabled((bool)ViewData["filtering"]))
        .Groupable(grouping => grouping.Enabled((bool)ViewData["grouping"]))
        .Footer((bool)ViewData["showFooter"])
        .ClientEvents(events => events.OnComplete("Assessments_onComplete"))
        .Groupable(settings => settings.Groups(g => { g.Add(model => model.NewsCategoryName); }))
        .ClientEvents(events => events.OnDataBound("Grid_onDataBound"))
)

</div>
<script src="@Url.Content("~/Scripts/indo.common.js")" type="text/javascript"></script>
@if (false)
{
    <script src="../../Scripts/jquery-1.7.2-vsdoc.js" type="text/javascript"></script>
}
<script type="text/javascript">
    function Grid_onDataBound(e) {
        $('img[alt="img-media-newspaper"]').each(function () {
            var currentTD = $(this).parent();
            var isRadio = $(this).parent().next().html();
            var isTV = $(this).parent().next().next().html();
            var isOnlineNews = $(this).parent().next().next().next().html();
            var isOnline = $(this).parent().next().next().next().next().html();
            if (isRadio === 'true') {
                $(this).attr('src', '/Content/img/radio2424.png');
            }
            else if (isTV === 'true') {
                $(this).attr('src', '/Content/img/tivi2424.png');
            }
            else if (isOnlineNews === 'true') {
                $(this).attr('src', '/Content/img/news2424.png');
            }

            if (isOnline === 'true') {
                $(currentTD).append('<img src="/Content/img/ie2424.png" alt="internet" />');
            }
        });
        $('a[rel="link-title"]').each(function () {
            var link = $(this).parent().next().html();
            var mark = $(this).parent().next().next().html();
            $(this).attr('href', link);
            $(this).attr('title', 'Average Mark: ' + mark);
        });
        $(".t-grid-content a[title]").tooltip();
    }

</script>